package com.zkingsoft.services.impl;

import com.zkingsoft.services.BusParamService;
import com.zkingsoft.services.FlowCzService;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.model.FlowCz;
import com.zkingsoft.model.Users;
import com.zkingsoft.constance.Dictionary;
import com.zkingsoft.dao.FlowCzDao;
import com.zkingsoft.dao.UsersDao;
import com.zkingsoft.exception.GlobleException;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-10-07 08:53
 */
@Service("flowCzService")
public class  FlowCzServiceImpl implements    FlowCzService  {

	
	@Autowired
	private FlowCzDao flowCzDao;
	
	@Autowired
	private UsersDao usersDao;
	
	@Autowired
	private BusParamService busParamService;
	
	/**
	 * 
	* @Description: 用户查看房源消耗金币
	* @author:姜友瑶
	* @param flowCz
	* @return    
	* 返回类型  int    
	* @date 2016年10月11日
	 */
	@Override
	public int userLookFy(FlowCz flowCz){
		
		//获取查看房源需要消耗的金币
		Integer jb= Integer.parseInt( busParamService.findValueByCode(Dictionary.PARAM_CODE_CKXH));
		
		Users user=usersDao.selectById(flowCz.getUserId());
		
		if(user.getAge()==null||user.getAge()<jb){
			throw new GlobleException("金币不足");
		}else{
			user.setAge(user.getAge()-jb);
			//更新用户信息
			usersDao.update(user);
			return flowCzDao.insert(flowCz);
		}
	}
	
	
	
	@Override
	public int add(FlowCz flowCz){
		
		return flowCzDao.insert(flowCz);
		
	}
   	
    @Override
	public int modify(FlowCz flowCz){
	
		return flowCzDao.update(flowCz);
	
	}
	
	@Override
	public int remove(List<Long> list){
	
		return flowCzDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long id){
	
		return flowCzDao.deleteById(id);
	
	}
	
	@Override
	public int removeByModel(FlowCz flowCz){
	
		return flowCzDao.deleteByModel(flowCz);
	
	}
	
	
	@Override
	public List<FlowCz> findInPage(FlowCz flowCz,  PaginationVO pageVo){
	
		return flowCzDao.selectInPage(flowCz , pageVo);
	
	}
	
	@Override
	public List<FlowCz> findByModel(FlowCz flowCz){
	
		return flowCzDao.selectByModel(flowCz);
	
	}
	
	@Override
	public int  findTotal(FlowCz flowCz){
	
		return flowCzDao.selectTotalRecord(flowCz);
	
	}
	
	@Override
	public FlowCz  findById(Long id){
	
		return flowCzDao.selectById(id);
	
	}

   	
	
	
}